/**
 * This program is free software under the terms and services of the GNU
 * General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your opinion) any later version
 *
 * This program is distributed in the hope that it will be useful, but without any warranty;
 * even implied warranty of merchantability or fitness for a particular purpose.  See the GNU
 * General Public License for more information
 */

package org.sdnngaming.sdnngaming.bukkit;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.sdnngaming.sdnngaming.core.PacketManager;
import org.sdnngaming.sdnngaming.core.PluginManager;

/**
 * Bukkit plugin is primary entry point when the plugin is run.
 * As this is not to replace the Bukkit API, the API itself should
 * allow the smoothest way to transition to any new plugin models
 */
public class Plugin extends JavaPlugin {

    /**
     * This will store the PluginManager instance which contains the majority of primary
     * code that will be used in the API
     */
    private PluginManager m_pPluginManager;

    /**
     * Stores a static instance of this class in order to other class's to
     * access it
     */
    private static Plugin s_pSingleton;

    /**
     * This will allow us to communicate to through protocol lib, which
     * which is used to help manage packets going in and out of the server
     */
    private static ProtocolManager m_pProtocolManager;

    /**
     * This method is called when the plugin gets enabled by the server.
     * We will not use onLoad(), as it's the intention to restart all instances
     * when the server gets reloaded
     *
     * Goal is to initialize PluginManager and protocol manager
     */
    @Override
    public void onEnable (){
        s_pSingleton = this;
        m_pPluginManager = new PluginManager ();
        m_pProtocolManager = ProtocolLibrary.getProtocolManager ();

        new PacketManager (true);
    }

    /**
     * This will allow us to access the instance which we store the protocol manager.
     * Use this method to access anything dealing with the protocol manager as it is
     * initialized in the onEnable() method
     *
     * @return Protocol Manager instance
     */
    public static ProtocolManager getProtocolManager (){
        return m_pProtocolManager;
    }

    /**
     * This method will allow other classes to get access to this class instance
     *
     * @return This class instance
     */
    public static Plugin getInstance (){
        return s_pSingleton;
    }
}
